import { Injectable } from '@angular/core';
import { StateMachineService } from "@farris/command-services";
import { FrameContext } from '@farris/devkit';
import { BefRepository, ResponseInfo } from '@farris/bef';
import { FormMessageService, FormNotifyService, CommandService, FormLoadingService, BeActionService } from '@farris/command-services';
import { EMPTY, of } from 'rxjs';
import { tap, map, switchMap } from 'rxjs/operators';

@Injectable()
export class SbssbxFormFrmControllerService {
  constructor(
    private frameContext: FrameContext,
    private messageService: FormMessageService,
    private beActionService: BeActionService,
    public stateMachineService: StateMachineService,
    public formNotifyService: FormNotifyService,
    private commandService: CommandService,
    public loadingService: FormLoadingService
  ) {

  }

  /**
   * 新增数据
   * @remarks 
   * @returns 
   */
  addData(): any {
    const context = this.frameContext;
    const bindingData = context.bindingData;
    let id = context.bindingData.getValue(['id'])
    const rep = this.frameContext.repository as BefRepository<any>;
    const xzdatas = this.frameContext.viewModel.uiState['xzdatas'];
    let tzDadas = []
    debugger;
    for (let item of xzdatas) {
      let wzbh = item.wzbh;
      let wzmc = item.wzmc;
      let dj = item.dj;
      tzDadas.push({
        bjbh:wzbh,
        bjmc:wzmc,
        bjjg:dj,
        bjly:'0'
      })
      // bindingData.setValue(['bjxxs', 'bjbh'], wzbh, true, true);
      // bindingData.setValue(['bjxxs', 'bjmc'], wzmc, true, true);
      // bindingData.setValue(['bjxxs', 'bjjg'], dy, true, true);
      // bindingData.setValue(['bjxxs', 'bjly'], '供应链', true, true);
    }
    rep.batchAppendByPath('/' + id + '/bjxxs', tzDadas).subscribe()
  }
}
